<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BOSS.Framework.Search.Result.ISearchResult>" %>
<%@ Import Namespace="BOSS.Domain.Products" %>
<%@ Import Namespace="BOSS.Web.Extensions" %>

<%
    var data = new
    {
        totalCount = Model.TotalCount,
        rows = Model.UnderlayerItems.OfType<ConsumptionRecord>().Select(x => new
        {
            Id = x.Id,
            Url = Url.Action("ConsumptionRecordDetails", "Product", new { id = x.Id }),
            SerialNumber = x.SerialNumber,
            CustomerCard = new 
            {
                Id = x.CustomerCard == null ? 0 : x.CustomerCard.Id,
                CardNumber = x.CustomerCard == null ? "" : x.CustomerCard.CardNumber,
                Cardholder = new 
                {
                    Id = (x.CustomerCard == null || x.CustomerCard.Cardholder == null) ? 0 : x.CustomerCard.Cardholder.Id,
                    Name = (x.CustomerCard == null || x.CustomerCard.Cardholder == null) ? "" : x.CustomerCard.Cardholder.Name
                }
            },
            CustomerAccount = new 
            { 
                Id = x.CustomerAccount == null ? 0 : x.CustomerAccount.Id,
                Url = Url.Action("CustomerAccountDetails", "Customer", new { id = (x.CustomerAccount == null ? 0 : x.CustomerAccount.Id) }),
                AccountNumber = x.CustomerAccount == null ? "" : x.CustomerAccount.AccountNumber,
                Customer = new 
                {
                    Id = (x.CustomerAccount == null || x.CustomerAccount.Customer == null) ? 0 : x.CustomerAccount.Customer.Id,
                    Name = (x.CustomerAccount == null || x.CustomerAccount.Customer == null) ? "" : x.CustomerAccount.Customer.Name,
                }
            },
            Creator = new 
            {
                Id = x.Creator == null ? 0 : x.Creator.Id,
                EmployeeId = x.Creator == null ? "" : x.Creator.EmployeeId, 
                FullName = x.Creator == null ? "" : x.Creator.FullName, 
            },
            CreateTime = Html.EncodeDateTime(x.CreateTime)
        })
    };
%>
<%= Html.ToJson(data) %>